//
//  YbrDlnaMusic.m
//  wifibox
//
//  Created by os X 10.9 on 15-1-14.
//  Copyright (c) 2015年 yinbaner. All rights reserved.
//

#import "YbrDlnaMusic.h"
#import "YbrHTTPServiceUtil.h"

@implementation YbrDlnaMusic
// 将MusicItem转换为DLNAMusic
+(YbrDlnaMusic *) musicItemToDlnaMusic:(YbrMusicItem *) musicItem position:(int) position {
    if(musicItem == nil) {
        return nil;
    }
    
    YbrDlnaMusic *dlnaMusic =   [[YbrDlnaMusic alloc] init];
    dlnaMusic.id            =   [NSString stringWithFormat:@"%i" , musicItem.musicId];
    dlnaMusic.name          =   musicItem.musicName;
    dlnaMusic.singerName    =   musicItem.singername;
    dlnaMusic.albumName     =   musicItem.albumname;
    
    if(musicItem.type == Type_SD) {
        dlnaMusic.url       =   musicItem.downloadurl;
    }else {
        if(![musicItem.downloadurl hasPrefix:@"/udisk"]) {
            if([musicItem.downloadurl hasPrefix:@"http"]) {
                dlnaMusic.url = musicItem.downloadurl;
            }else {
//                dlnaMusic.url = [NSString stringWithFormat:@"%@%@" ,MP3Url ,musicItem.downloadurl];
            }
        } else {
            dlnaMusic.url = [YbrHTTPServiceUtil getHttpPath:musicItem.file];
        }
    }
    
//    if([NSString isEmpty:dlnaMusic.url] && ![NSString isEmpty:dlnaMusic.saveurl]) {
//        dlnaMusic.url = [YbrHTTPServiceUtil getHttpPath:musicItem.file];
//    } else {
//        if(musicItem.type != Type_SD) {
//            if([musicItem.singername isEqualToString:YbrDefualSingerName]) {    // 表示是网络歌曲
////                if([musicItem.musicName hasSuffix:@".mp3"]) {
////                    dlnaMusic.saveurl = [NSString stringWithFormat:@"%@%@" ,FTPDownTemp ,musicItem.musicName];
////                }else {
////                    dlnaMusic.saveurl = [NSString stringWithFormat:@"%@%@%@" ,FTPDownTemp ,musicItem.musicName ,@".mp3"];
////                }
//            }else { // 课程文件是要保存到本地的
//                if([musicItem.musicName hasSuffix:@".mp3"]) {
//                    dlnaMusic.saveurl = [NSString stringWithFormat:@"%@%@" ,FTPDownTemp , [YbrMD5 md5HexDigest:[NSString stringWithFormat:@"%@%@" ,musicItem.albumname ,musicItem.musicName]]];
//                } else {
//                    dlnaMusic.saveurl = [NSString stringWithFormat:@"%@%@%@" ,FTPDownTemp , [YbrMD5 md5HexDigest:[NSString stringWithFormat:@"%@%@" ,musicItem.albumname ,musicItem.musicName]],@".mp3"];
//                }
//            }
//        }
//    }
    
    //NSLog(@"-----------11111111111111111122222222222333333333333--------------------------图片----------%@",musicItem.img);
    
    
//    dlnaMusic.img       = musicItem.img;
//    dlnaMusic.duration  = [YbrTimerUtil makeClockChooseTimeStr:musicItem.duration];
//    dlnaMusic.position  = position;
    
    return dlnaMusic;
}

@end
